package aod.android.com.bernay.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import aod.android.com.bernay.R;
import aod.android.com.bernay.view.V;
import chen.lion.hilib.base.HiBaseActivity;
import cn.jpush.android.api.JPushInterface;
import me.leefeng.promptlibrary.PromptDialog;

public abstract class BernayBaseActivity extends HiBaseActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        promptDialog = new PromptDialog(this);
    }

    public void initTitle(String name, boolean isBack){
        initTitle(name,null,0,null,isBack);
    }


    public void initTitle(String name){
        initTitle(name,null,0,null,true);
    }
    public void initTitle(String name,int right){
        initTitle(name,null,right,null,false);
    }
    public void initTitle(String name,String rightName,View.OnClickListener onClickListener){
        initTitle(name,rightName,0,onClickListener,true);
    }

    public void initTitle(String name,int right,View.OnClickListener onClickListener){
        initTitle(name,null,right,onClickListener,true);
    }

    public void goneTitle(boolean isGone){
        if(isGone) {
            findViewById(R.id.lay_title).setVisibility(View.GONE);
        }else{
            findViewById(R.id.lay_title).setVisibility(View.VISIBLE);
        }
    }

    private void initTitle(String name,String rightName, int right, View.OnClickListener onClickListener,boolean isBack){

        TextView titleTv = findViewById(R.id.title_tv_name);

        if(titleTv == null){
            return;
        }

        titleTv.setText(name);

        findViewById(R.id.title_iv_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });

        if(!isBack){
            findViewById(R.id.title_iv_back).setVisibility(View.GONE);
        }

        if(!TextUtils.isEmpty(rightName)){
            TextView rightTv = findViewById(R.id.title_tv_right);
            if(rightTv == null){
                return;
            }
            rightTv.setText(rightName);
            rightTv.setOnClickListener(onClickListener);
            rightTv.setVisibility(View.VISIBLE);
        }


        if(right != 0){
            ImageView rightIv = findViewById(R.id.title_iv_right);
            if(rightIv == null){
                return;
            }
            rightIv.setImageResource(right);
            rightIv.setOnClickListener(onClickListener);
            rightIv.setVisibility(View.VISIBLE);
        }
    }



    PromptDialog promptDialog ;
    public void showLoding(){
        showLoding("请稍后");
    }

    public void showLoding(String content){

        if(promptDialog!=null) {
            promptDialog.showLoading(content);
        }
    }

    public void showSuccess(String  content){
        if(promptDialog!=null) {
            promptDialog.showSuccess(content);
        }
    }

    public void showSuccess(){
        if(promptDialog!=null) {
            promptDialog.showSuccess("成功");
        }
    }

    public void showError(){
        if(promptDialog!=null) {
            promptDialog.showError("失败");
        }
    }


    public void showError(String content){
        if(promptDialog!=null) {
            promptDialog.showError(content);
        }
    }
    public void showToast(String content) {
        Toast.makeText(this, content, Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onResume() {
        super.onResume();
        JPushInterface.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        JPushInterface.onPause(this);
    }
}
